<?php include _include(APP_PATH.'view/htm/header.inc.htm');?>

<div class="row vh-100 justify-content-center align-items-center my-n5">
	<!--{hook user_create_start.htm}-->
	<div class="col-lg-7 mx-auto">
		<!--{hook user_create_card_before.htm}-->
		<div class="card">
			<div class="card-header h4 text-center">
				<?php echo lang('user_create');?>
			</div>
			<div class="card-body">
				<form action="<?php echo url('user-create');?>" method="post" id="form">
					<div class="form-group input-group">
						<div class="input-group-prepend">
							<span class="input-group-text"><i class="icon-user icon-fw"></i></span>
						</div>
						<input type="text" class="form-control" placeholder="<?php echo lang('username');?>" name="username" id="username" required>
					</div>

					<!--{hook user_create_username_after.htm}-->

					<div class="media">
						<div class="media-body">
							<div class="form-group input-group">
								<div class="input-group-prepend">
									<span class="input-group-text"><i class="icon-lock icon-fw"></i></span>
								</div>
								<input type="password" class="form-control" placeholder="<?php echo lang('password');?>" name="password" id="password" required>
							</div>
						</div>
					</div>

					<!--{hook user_create_password_after.htm}-->

					<div class="form-group input-group">
						<div class="input-group-prepend">
							<span class="input-group-text"><i class="icon-envelope icon-fw"></i></span>
						</div>
						<input type="email" class="form-control" placeholder="<?php echo lang('email');?>" name="email" id="email" required>
					</div>

					<!--{hook user_create_email_after.htm}-->

					<?php if($conf['user_create_email_on']) { ?>
					<div class="media">
						<div class="media-body">
							<div class="form-group input-group">
								<div class="input-group-prepend">
									<span class="input-group-text"><i class="icon-barcode icon-fw"></i></span>
								</div>
								<input type="text" class="form-control" placeholder="<?php echo lang('verify_code');?>" name="code" id="code">
							</div>
						</div>
						<div class="align-self-center ml-1">
							<button type="submit" class="btn btn-primary btn-sm ml-3 form-group" id="sendcode" data-loading-text="<?php echo lang('sending');?>...">
								<?php echo lang('send_verify_code');?>
							</button>
						</div>
					</div>
					<?php } ?>

					<div class="form-group">
						<button type="submit" class="btn btn-primary btn-block" id="submit" data-loading-text="<?php echo lang('submiting');?>..." <?php if($conf['user_create_email_on']) { ?>disabled<?php } ?>>
						<?php echo lang('next_step');?>
						</button>
					</div>
					<!--{hook user_create_submit_after.htm}-->

					<div class="media">
						<div>
							<!--{hook user_create_form_footer_left.htm}-->
						</div>
						<div class="media-body text-right">
							<!--{hook user_create_form_footer_right_start.htm}-->
							<a href="<?php echo url('user-login');?>" class="text-muted">
								<small>
									<?php echo lang('user_login');?>
								</small>
							</a>
							<?php if(!empty($conf['user_resetpw_on'])) { ?>
							<a href="<?php echo url('user-resetpw');?>" class="text-muted ml-3">
								<small>
									<?php echo lang('forgot_pw');?>
								</small>
							</a>
							<?php } ?>
							<!--{hook user_create_form_footer_right_end.htm}-->
						</div>
					</div>

				</form>
			</div>
		</div>
		<!--{hook user_create_card_after.htm}-->
	</div>
</div>

<?php include _include(APP_PATH . 'view/htm/footer.inc.htm');?>

<script src="<?php echo view_path();?>js/md5.js"></script>

<script>
    var safe_token = '<?php echo GLOBALS('safe_token');?>';
	var body = $('body');
    var referer = '<?php echo http_referer();?>';
	body.on('click', '#sendcode', function() {
		var jthis = $(this);
		var jform = $('#form');
        jform.reset();
		jthis.button('loading');
        var postdata = jform.serializeObject();
        postdata.safe_token = safe_token;
        $.xpost(xn.url('user-send_code-user_create'), postdata, function(code, message) {
            if(0 == code) {
                $('#code').focus();
				jthis.button('<?php echo lang('user_send_successfully');?> 60 ');
				$('button#submit').button('reset');
                var t = 60; /*倒计时，重新发送*/
                var handler = setInterval(function() {
					jthis.button('<?php echo lang('user_send_successfully');?> '+(--t)+' ');
                    if(0 == t) {
                        clearInterval(handler);
						jthis.button('reset');
                    }
                }, 1000);
            } else if(code < 0) {
                $.alert(message, -1);
				jthis.button('reset');
            } else {
                jform.find('[name="'+code+'"]').alert(message).focus();
				jthis.button('reset');
            }
        });
        return false;
    });

	body.on('submit', '#form', function() {
        var jthis = $(this);
        var jsubmit = jthis.find('#submit');
        jsubmit.button('loading');
        var postdata = jthis.serializeObject();
        postdata.password = $.md5(postdata.password);
        postdata.safe_token = safe_token;
        $.xpost(jthis.attr('action'), postdata, function(code, message) {
            if(0 == code) {
                jsubmit.button(message).delay(1000).location(referer);
            } else if(xn.is_number(code)) {
                $.alert(message);
                jsubmit.button('reset');
            } else {
				jthis.find('[name="'+code+'"]').alert(message).focus();
                jsubmit.button('reset');
            }
        });
        return false;
    });
</script>

<!--{hook user_create_js.htm}-->